import { http } from "@/utils/http";

export type ResultType = ReplaceTargetType<any[]>;

export const getList = (current, size, params) => {
  return http.request<any>({
    url: "/cupSystemApi/role/list",
    method: "get",
    params: {
      ...params,
      current,
      size,
    },
  });
};

export const grantTree = () => {
  return http.request<any>({
    url: "/cupSystemApi/menu/grant-tree",
    method: "get",
  });
};

export const grant = (roleIds, menuIds, dataScopeIds) => {
  return http.request<any>({
    url: "/cupSystemApi/role/grant",
    method: "post",
    data: {
      roleIds,
      menuIds,
      dataScopeIds,
      apiScopeIds: [],
    },
  });
};

export const remove = (ids) => {
  return http.request<any>({
    url: "/cupSystemApi/role/remove",
    method: "post",
    params: {
      ids,
    },
  });
};

export const add = (row) => {
  return http.request<any>({
    url: "/cupSystemApi/role/submit",
    method: "post",
    data: row,
  });
};

export const update = (row) => {
  return http.request<any>({
    url: "/cupSystemApi/role/submit",
    method: "post",
    data: row,
  });
};

export const detail = (id) => {
  return http.request<any>({
    url: "/cupSystemApi/role/detail",
    method: "get",
    params: {
      id,
    },
  });
};

export const getRole = (roleIds) => {
  return http.request<any>({
    url: "/cupSystemApi/menu/role-tree-keys",
    method: "get",
    params: {
      roleIds,
    },
  });
};

export const getRoleTree = () => {
  return http.request<any>({
    url: "/cupSystemApi/role/tree",
    method: "get",
  });
};
